# -*- coding: utf-8 -*-
# @Time    : 2024/8/30 下午2:20
# @Author  : liujun
# @Email   : 2592730854@qq.com
# @File    : source_add_page.py
# @Software: PyCharm

from selenium import webdriver
from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select
from  selenium.webdriver.common.alert import  Alert

class SourceAddPage(BasePage):
    """添加线索"""
    url="/crm/index.php?m=leads&a=add"
    source_head_locator= (By.ID, "owner_name")  # 负责人
    source_head_circle_locator = (By.CSS_SELECTOR, "#d_content > tr:nth-child(1) > td:nth-child(1) > input[type=radio]")  # 选择负责人圈
    source_head_ok_btn_locator = (By.CSS_SELECTOR,
                                  "body > div:nth-child(14) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1)")  # 选择负责人弹框ok按钮
    courtesy_title_locator = (By.ID, "saltname")  # 尊称下拉框
    contacts_locator = (By.ID, "contacts_name")  # 联系人姓名
    source_push_pool_locator = (By.ID, "remove")  # 放入线索池
    save_locator = (By.CSS_SELECTOR, "#form1 > table > tfoot > tr > td > input:nth-child(1)")  # 保存
    company_name_locator = (By.ID, "name")  # 公司名
    email_locator = (By.ID, "email")  # 邮箱
    next_time_locator = (By.ID, "nextstep_time")  # 下次联系时间框



    def click_source_head(self):
        """点击负责人框"""
        self.driver.find_element(*self.source_head_locator).click()
    def click_source_head_circle(self):
        """点击选择负责人圈"""
        self.driver.find_element(*self.source_head_circle_locator).click()
    def click_source_head_ok_btn(self):
        """点击选择负责人弹框ok按钮"""
        self.driver.find_element(*self.source_head_ok_btn_locator).click()
    def select_courtesy_title(self,choose):
        """尊称"""
        courtesy_title_element = self.driver.find_element(*self.courtesy_title_locator)
        courtesy_title_obj = Select(courtesy_title_element)
        courtesy_title_obj.select_by_value(choose)

    def input_contacts(self,contacts):
        """输入联系人"""
        self.driver.find_element(*self.contacts_locator).send_keys(contacts)
    def input_company_name(self,company_name):
        """输入公司名"""
        self.driver.find_element(*self.company_name_locator).send_keys(company_name)
    def click_save(self):
        """点击保存"""
        self.driver.find_element(*self.save_locator).click()
    def click_source_push_pool(self):
        """点击放入线索池"""
        self.driver.find_element(*self.source_push_pool_locator).click()

    def  input_email(self,email):
        """输入邮箱"""
        self.driver.find_element(*self.email_locator).send_keys(email)
    def next_time(self,next_time):
        """下次联系时间"""
        next_time_element = self.driver.find_element(*self.next_time_locator)
        next_time_element.click()
        js = "document.getElementById('nextstep_time').removeAttribute('readonly')"
        self.driver.execute_script(js)
        next_time_element.clear()
        next_time_element.send_keys(next_time)

    def clear(self):
        """清除文本"""
        self.driver.clear()

    def accept(self):
        """确定弹框"""
        self.driver.switch_to.alert.accept()




